import React from 'react';
import { getJobDetail } from '@/services/organization';

const useJobDetail = query => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(false);

    const fetchData = async () => {
        setLoading(true);

        const { data: detail, code } = (await getJobDetail(query.positionCode)) || {};

        if (code === 10000) {
            setData(detail);
        }

        setLoading(false);
    };

    React.useEffect(() => {
        if (query.positionCode) {
            fetchData();
        }
    }, [query.positionCode]);

    return [loading, data, setLoading];
};

export default useJobDetail;
